﻿@using lsc.Model
@using lsc.Model.Enume
@model List<SalesProject>
@{
    ViewData["Title"] = "销售项目管理";
    Layout = "~/Pages/_Layout.cshtml";
    List<EnterCustomer> enterlist = ViewBag.enterlist;
    Dictionary<int, double> recpayDic = ViewBag.recpayDic;
}
<blockquote class="layui-elem-quote">
    销售项目管理
    <a class="layui-btn layui-btn-normal" href="/EnterCustom/AddEnterCustom?id=0">添加客户</a>
</blockquote>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>销售项目综合查询</legend>
</fieldset>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" method="post" id="queryform" action="/EnterCustom/SalesProjectIndex">
            <div class="layui-col-md4 query-from-item">
                <label class="layui-form-label">项目标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="Title" class="layui-form-text layui-input" value="@ViewBag.Title" />
                </div>
            </div>
            <div class="layui-col-md4 query-from-item">
                <label class="layui-form-label">项目状态</label>
                <div class="layui-input-inline">
                    <select class="layui-form-select" name="ProjectState">
                        <option value=""></option>
                        <option value="0"  @(ViewBag.ProjectState==0 ? "selected":"")>进行中</option>
                        <option value="1"  @(ViewBag.ProjectState==1 ? "selected":"")>成功</option>
                        <option value="2"  @(ViewBag.ProjectState==2 ? "selected":"")>失败</option>
                        <option value="3"  @(ViewBag.ProjectState==3 ? "selected":"")>搁置</option>
                        <option value="4"  @(ViewBag.ProjectState==4 ? "selected":"")>放弃</option>
                    </select>
                </div>
            </div>
            <div class="layui-col-md4 query-from-item">
                <label class="layui-form-label">项目类型</label>
                <div class="layui-input-inline">
                    <select class="layui-form-select" name="ProjectType">
                        <option value=""></option>
                        <option value="1" @(ViewBag.ProjectType == 1 ? "selected":"")>大型项目</option>
                        <option value="2" @(ViewBag.ProjectType == 2 ? "selected":"")>中型项目</option>
                        <option value="3" @(ViewBag.ProjectType == 3 ? "selected":"")>小型项目</option>
                    </select>
                </div>
            </div>
            <div class="layui-col-md4 query-from-item">
                <label class="layui-form-label">立案开始时间</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="starttime" placeholder="yyyy-MM-dd" name="ProjectStartTime" value="@(ViewBag.ProjectStartTime)" />
                </div>
            </div>
            <div class="layui-col-md4 query-from-item">
                <label class="layui-form-label">立案截止时间</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="endtime" placeholder="yyyy-MM-dd" name="ProjectEndTime" value="@(ViewBag.ProjectEndTime)" />
                </div>
            </div>
            <div class="layui-col-md4 query-from-item">
                <div class="layui-input-block">
                    <input type="hidden" name="page" value="@(ViewBag.pageIndex)" />
                    <button class="layui-btn" lay-submit lay-filter="*">查询</button>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-row">
        <table class="layui-table">
            <thead>
                <tr>
                    <th>项目标题</th>
                    <th>项目概要</th>
                    <th>客户</th>
                    <th>项目状态</th>
                    <th>项目类型</th>
                    <th>立项时间</th>
                    <th>项目金额</th>
                    <th>已回款</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @if (Model != null && Model.Count > 0)
                {
                    foreach (var info in Model)
                    {
                        string entername = string.Empty;
                        if (enterlist!=null)
                        {
                            var enter = enterlist.FirstOrDefault(x => x.ID == info.EnterCustomerID);
                            if (enter!=null)
                            {
                                entername = enter.EnterName;
                            }
                        }
                        double amt = 0;
                        if (recpayDic!=null && recpayDic.ContainsKey(info.ID))
                        {
                            amt = recpayDic[info.ID];
                         }
                        <tr>
                            <td>@info.Title</td>
                            <td>@info.ProjectAbstract</td>
                            <td>@entername</td>
                            <td><a href="/EnterCustom/GetSalesProjectStateLog?SalesProjectID=@(info.ID)">@info.ProjectState.TryToStr()</a></td>
                            <td>@info.ProjectType.TryToStr()</td>
                            <td>@info.ProjectTime.ToString("yyyy-MM-dd")</td>
                            <td>@info.ProjectAmt</td>
                            <td>@amt</td>
                            <td>
                                <div class="layui-btn-group">
                                    <a href="javascript:;" onclick="updatestate('@info.ID')" class="layui-btn layui-btn-small">修改项目状态</a>
                                    <a href="javascript:;" class="layui-btn layui-btn-small" onclick="addReceoverdPay('@info.ID')">添加回款记录</a>
                                </div>
                            
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
        <div id="page"></div>
    </div>
</div>
@section Scripts
    {
    <script type="text/javascript">
        var layer, form
        layui.use(['form', 'element', 'layer', 'laydate','laypage'], function () {
            layer = layui.layer
            form = layui.form
            laydate = layui.laydate
            var laypage = layui.laypage

            laydate.render({
                elem: '#starttime'
            });

            laydate.render({
                elem: '#endtime'
            });

            //form.on('submit(*)', function (data) {
            //    $.post('/EnterCustom/SalesProjectList', data.field, function (res) {
            //        $("#content_table").html(res)
            //    })
            //    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            //});

            //分页
            laypage.render({
                elem: 'page' //分页容器的id
                , count: @(ViewBag.Count) //总页数
                ,limit:20
                , skin: '#1E9FFF' //自定义选中色值
                //,skip: true //开启跳页
                ,curr: @(ViewBag.pageIndex) //获取起始页
                ,jump: function (obj, first) {
                    console.log(obj)
                    if (!first) {
                        $("input[name='page']").val(obj.curr)
                        $("#queryform").submit();
                    }
                }
                , hash: 'fenye' //自定义hash值
            });
        });

        updatestate = function (id) {
            layer.open({
                type: 2,
                title: '更新销售项目状态',
                shadeClose: true,
                shade: 0.8,
                area: ['1200px', '70%'],
                content: '/EnterCustom/AddSalesProjectStateLog?SalesProjectID=' + id
            });
        }
        addReceoverdPay = function (id) {
            layer.open({
                type: 2,
                title: '添加回款记录',
                shadeClose: true,
                shade: 0.8,
                area: ['400px', '40%'],
                content: '/EnterCustom/AddReceovedPayLog?SalesProjectID=' + id
            });
         }
    </script>
    }
